using TMPro;
using UnityEngine;

namespace LST_Test
{
    /// <summary>
    /// 创建测试地图Node
    /// </summary>
    public class CreateGrid : MonoBehaviour
    {
        public static readonly int Width = 45;
        public static readonly int Height = 45;

        [SerializeField] public GameObject cube1;
        [SerializeField] public GameObject cube2;

        public GameObject[] cube = new GameObject[Width * Height];

        public void Start()
        {
            for (int i = 0; i < Width; ++i)
            {
                for (int j = 0; j < Height; ++j)
                {
                    var ori = (i + j) % 2 == 0 ? cube1 : cube2;
                    var go = GameObject.Instantiate(ori, transform, true);
                    go.transform.position = new Vector3(i, 0, j);
                    go.name = $"{i},{j}";
                    var txt = go.GetComponentInChildren<TextMeshPro>();
                    txt.text = go.name;
                    cube[i + j] = go;
                }
            }

            var testAStarComponentGo = GameObject.Find("TestAStarSearch");
            if (testAStarComponentGo.Equals(null))
            {
                return;
            }

            var testAStarComponent = testAStarComponentGo.GetComponent<TestAStarSearch>();
            testAStarComponent.CreateAStarGrid(this);
        }
    }
}